From 1140b7ad2b5bb98a638c487ce8bc61550fd56da8 Mon Sep 17 00:00:00 2001 From: robertl Date: Mon, 21 Feb 2011 16:55:33 +0000 Subject: [PATCH] Improve handling of bogus NMEA. --- gpsbabel/nmea.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gpsbabel/nmea.c b/gpsbabel/nmea.c index df3da62bd..a3bac09b5 100644 --- a/gpsbabel/nmea.c +++ b/gpsbabel/nmea.c @@ -532,8 +532,12 @@ gprmc_parse(char *ibuf) } /* Skip past nine commas in ibuf to reach the dmy value */ - for (dmybuf=ibuf,i=0; i<9 && dmybuf != NULL; i++) { + for (dmybuf=ibuf,i=0; i<9; i++) { dmybuf= strchr(dmybuf, ','); + if(dmybuf==NULL) { + /* If we run out of commas, the sentence is invalid. */ + return; + } dmybuf++; } @@ -910,6 +914,12 @@ nmea_parse_one_line(char *ibuf) had_checksum = 0; return; } + + if(strstr(tbuf+1,"$")!=NULL) + { + /* If line has more than one $, there is probably an error in it. */ + return; + } /* @@@ zmarties: The parse routines all assume all fields are present, but the NMEA format allows any field to be missed out if there is no data -- 2.30.2